import request from '@/common/request.js'
import {
	getToken,
	setToken
} from '@/common/auth.js'

//获取token;
export function wxGetToken(re) {
	var token = getToken()
	if (!token) {
		// if (pUserId <= 0) {
		// 	var id = uni.getStorageSync('parentUserId')
		// 	pUserId = id;
		// }
		uni.login({
			provider: 'weixin',
			success(res) {
			console.log(res,1);
			let pars = uni.getStorageSync("parentId")
				var data = {
					code: res.code,
					// signature:re.signature,
					// encryptedData:	re.encryptedData,
					// iv:re.iv,
					// rawData:re.rawData
				}
				console.log(data,2); 
				 request.urlRequest({
					url: '/api/LoinApi/WxOAuth',
					method: 'POST',
					data
				}).then((rs) => {
					if (rs.code == 200) {
						// uni.setStorageSync("token", rs.data.data);
						setToken(rs.data)
						// var pages = getCurrentPages() //获取加载的页面
						// var currentPage = pages[pages.length - 1] //获取当前页面的对象

						// let curParam = pages[pages.length - 1]
						// 	.options; //获取路由参数     //   {"userId":"1000007"}
						// // 拼接参数
						// let param = ''
						// for (let key in curParam) {
						// 	param += '&' + key + '=' + curParam[key]
						// }
						// var now_url = currentPage.route + '?' + param //当前页面url
						// console.log(now_url)
						// uni.reLaunch({
						// 	url: '/' + now_url
						// })
					}
				})
			}
		})
	}
}


//发送验证码 0-注册绑定手机号 
export function sendCode(phone, codeType) {
	return request.urlRequest({
		url: '/api/Login/SendCode?SmsType=' + codeType + '&Mobile=' + phone,
		method: 'post'
	})
}


